/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_EXT_STYLE_H_
#define TRI_EXT_STYLE_H_

#include <iostream>
#include <vector>
#include <string>
#include <map>

#include "../graphics.h" 
#include "../events.h"
#include "../base/logging.h"
#include "../base/xmlnode.h"
#include "common.h"

namespace tri {
namespace ui {


class extStyle{

public:
	extStyle();
	void clear();
	void copy(extStyle* style);
	void setBGImage(std::string image,int event = tri::NONE);
	std::string getBGImage(int event = tri::NONE);
	
	tri::graphics::TColor getColor(int event = tri::NONE );
	void setColor(int r, int g, int b, int a,int event = tri::NONE);
	
	void setSegmentInsets(float l, float t, float r, float b,int event = tri::NONE);
	tri::TRectangle* getSegmentInsets(int event = tri::NONE);
	
	void setImageInsets(float l, float t, float r, float b,int event = tri::NONE);
	tri::TRectangle* getImageInsets(int event = tri::NONE);
	
	void setInsets(float l, float t, float r, float b,int event = tri::NONE);
	tri::TRectangle* getInsets(int event = tri::NONE);
	
	void setTransitionTime(float t,int event = tri::NONE);
	
	tri::graphics::TColor getTextColor(int event = tri::NONE );
	void setTextColor(int r, int g, int b, int a,int event = tri::NONE);
	
	tri::graphics::TColor getTextBGColor(int event = tri::NONE );
	void setTextBGColor(int r, int g, int b, int a,int event = tri::NONE);
	
	int getFontSize(int event = tri::NONE );
	void setFontSize(int fs,int event = tri::NONE );
	
	int getTextAlignment(int event = tri::NONE );
	void setTextAlignment(int a,int event = tri::NONE );
	
	float getCharacterHeight(int event = tri::NONE );
	void setCharacterHeight(float ch,int event = tri::NONE );
	
	std::string getFont(int event = tri::NONE );
	void setFont(std::string f,int event = tri::NONE );
	
	
	
	class extState{
	public:
		extState();
		
		void clear();
		void copy(extState*);
		
		std::string mBGImage;
		tri::graphics::TColor mColor;
		tri::TRectangle mSegmentInsets;
		tri::TRectangle mImageInsets;
		tri::TRectangle mInsets;
		
		int mFontSize;
		float mCharacterHeight;
		std::string mFont;
		int mTextAlignment;
		tri::graphics::TColor mTextColor;
		tri::graphics::TColor mTextBGColor;
		
		float mAnimationTime;
	};
	
	/**
	 * Load styles form xml
	 *
	 * @param xmlFile XML defineing styles
	 */
	//static void InitStyles(std::string xmlFile);
	
	/**
	 * Load styles form xml
	 *
	 * @param xmlFile List of XML files defining styles
	 */
	//static void InitStyles(std::vector<std::string>& xmlFile);
	
	/**
	 * Return true if a style by the given name exists
	 * @return True if style exists
	 */
	static bool exists(std::string key);
	
	/**
	 * Create a new Style
	 * If style already exists this
	 * method will do nothing. use extStyle::exists() 
	 * to check if a style by a given name exists.
	 * @param style Style name
	 */
	static void createStyle(std::string style);
	
	/**
	 * Get a style by the given name
	 *
	 * @param Style
	 */
	static extStyle* getStyle(std::string style);
	

private:
	//storage for all style
	static std::map<std::string,extStyle> mGlobalStyles;
	
	extState* getState(int event = tri::NONE);
	void getStateGroup(std::vector<extState*>& states,int event);
		
	extState mDefaultState;
	extState mMouseOverState;
	extState mPressedState;
	extState mDragState;
	extState mFocusState;
	extState mDisabledState;
	extState mCheckedState;
};


void loadStyleFromXML(std::string xmlfile);
void loadXMLState(std::string xmlfile,tri::ui::extStyle* style,tri::TXMLNode*,int state);

}
}

#endif
